package com.fishleap.speaker;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author zlg
 */
public class SpeakMapper extends Mapper<LongWritable, Text, Text, SpeakBean> {

    Text outKey = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split("\t");
        // 取出设备id
        String deviceId = fields[0];
        // 取出自有和第三方时长数据
        long selfDuration = Long.parseLong(fields[fields.length - 3]);
        long thirdPartDuration = Long.parseLong(fields[fields.length - 2]);

        outKey.set(deviceId);
        SpeakBean outValue = new SpeakBean(selfDuration, thirdPartDuration);
        context.write(outKey, outValue);
    }
}
